package com.pwx.student.config;

import com.pwx.student.interceptor.MyAuthorizationInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Copyright (C),2021-2022,亚瑟王
 * FileName: MyMvcConfig
 * Author: saber
 * Date:2022/10/25 20:38
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
                //添加需要处理跨域的路径的映射
        registry.addMapping("/**")
                //允许所有的请求头,请求内容
                .allowedHeaders("*")
                //允许任意请求方式都可以 get post delete put
                .allowedMethods("*")
                //允许任意站点过来的请求都运行 http://ip:port
                .allowedOriginPatterns("*")
                // 允许 状态标识的传输 cookie
                .allowCredentials(true);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyAuthorizationInterceptor())
                .addPathPatterns("/**").excludePathPatterns("/login");
    }
}
